﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace HYSoft.Web
{
    public partial class bianpo_add : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                string type = Session["Usertype"] == null ? string.Empty : (string)Session["Usertype"];
                if (type != "单位用户")
                {
                    Response.Write("<script>alert('对不起，您没有增加边坡信息权限！');history.go(-1);</script>");

                }
                else
                {
                    GetJCD();
                }
            }
        }

        protected void GetJCD()
        {
            try
            {
                string sql = " user_index=" + Session["uid"].ToString() + "";
                DataSet ds = new BLL.usr2monitor().GetList(sql);
                ListItem item;
                foreach (DataRow row in ds.Tables[0].Rows)
                {
                    item = new ListItem();
                    item.Value = row["index"].ToString();
                    item.Text = row["m_area_name"].ToString() + "_" + row["addr"].ToString();
                    this.select1.Items.Add(item);
                }
            }
            catch
            {
                Response.Redirect("errorpage.htm");
            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            if (this.IsValid)
            {
                try
                {
                    Model.bpinfo bpinfo = new Model.bpinfo();
                    bpinfo.route_name = lxmc.Value.TrimStart().TrimEnd();
                    bpinfo.slop_constr_site = bpgd.Value.TrimStart().TrimEnd();
                    bpinfo.sec_location = pmwz.Value.TrimStart().TrimEnd();
                    bpinfo.ljbp_sec_id = int.Parse(select1.Value.TrimStart().TrimEnd());
                    bpinfo.bpgd = int.Parse(bpgaodu.Value.TrimStart().TrimEnd());
                    bpinfo.bppd = int.Parse(bppd.Value.TrimStart().TrimEnd());
                    bpinfo.ljhdmxs = ljhdmxs.Value.TrimStart().TrimEnd();
                    bpinfo.ljlx = ljlx.Value.TrimStart().TrimEnd();
                    bpinfo.ljkd = int.Parse(ljkd.Value.TrimStart().TrimEnd());
                    bpinfo.ljdzlx = ljdzlx.Value.TrimStart().TrimEnd();
                    bpinfo.ljfhgclx = ljfhgclx.Value.TrimStart().TrimEnd();
                    bpinfo.ljfhgccl = ljfhgccl.Value.TrimStart().TrimEnd();
                    new BLL.bpinfo().Add(bpinfo);
                    string sql = " areano='" + select1.Value.TrimStart().TrimEnd() + "'";
                    DataSet ds = new BLL.gprsNode().GetList(sql);
                    foreach (DataRow row in ds.Tables[0].Rows)
                    {
                        Model.bp_jz bpjzs = new BLL.bp_jz().GetModel(int.Parse(row["areano"].ToString()), int.Parse(row["mac"].ToString()));
                        if (bpjzs == null)
                        {
                            bpjzs = new Model.bp_jz();
                            bpjzs.ljbp_sec_id = int.Parse(row["areano"].ToString());
                            bpjzs.mac = int.Parse(row["mac"].ToString());
                            new BLL.bp_jz().Add(bpjzs);
                        }
                    }
                    Response.Write("<script>alert('边坡信息增加成功！')</script>");
                    Response.Redirect("bianpo_manage.aspx",false);
                }
                catch
                {
                    Response.Redirect("errorpage.htm");
                }
            }
        }
    }
}